<?php

namespace app\ports\controller;

use app\ports\controller\publics\Primarys;
use think\Db;

/**
 *  
 * Class
 * @package
 */
class Times
{

	/**
	 * 主账号运行 - 虚
	 */
	public function primarys()
	{
		try {
			// \app\ports\controller\publics\Primarys::instance()->handles();
			Primarys::instance()->handles();
			echo "运行正常...................！！！";
		} catch (\Exception $e) {
			echo $e->getMessage();
		}
	}

	/**
	 * 手动解锁 - 达标手机
	 */
	public function unlock()
	{
		try {
			$limitTimes = "2023-11";
			$currentTimes = strtotime(date("Y-m"));
			if ($currentTimes == strtotime($limitTimes)) {
				$arr = [
					// 2023-11-19 11:21:56
					// 2023-11-20 21:01:56
					// 2023-11-23 20:29:01
					// ["id" => 29, "times" => '1700364116'],
					// ["id" => 30, "times" => '1700485316'],
					["id" => 31, "times" => '1700742541']
				];
				$table  = "bonus_upgrade";
				$now = strtotime(date("Y-m-d H:i:s", time()));
				for ($i = 0; $i < count($arr); $i++) {
					$times = "";
					$update = [];
					$times = strtotime("+1 hour", $arr[$i]["times"]);
					if ($now > $arr[$i]["times"] && $now < $times) {
						// dump(date("Y-m-d H:i:s",  $arr[$i]["times"]) . "--------------" . date("Y-m-d H:i:s", $times));
						$check = Db::name($table)->where("id = " . $arr[$i]["id"]  . " and state = 2")->count();
						if ($check) {
							$update["state"] = 1;
							Db::name($table)->where("id = " . $arr[$i]["id"]  . " and state = 2")->update($update);
						}
					}
				}
			}
			echo "运行正常...................！！！";
		} catch (\Exception $e) {
		}
	}

	/**
	 * 手动添加 - 达标手机
	 */
	public function shoudong()
	{
		try {
			$limitTimes = "2023-11";
			$currentTimes = strtotime(date("Y-m"));
			if ($currentTimes == strtotime($limitTimes)) {
				$arr = [
					["id" => 210, "levs" => "P2",  "times" => '1700056805'],
					["id" => 184, "levs" => "P3",  "times" => '1700971205']
				];
				$table  = "bonus_upgrade";
				$times = '1698768000';
				$now = strtotime(date("Y-m-d H:i:s", time()));
				$end = strtotime("+1 hour", $now);
				// dump(date('Y-m-d H:i:s', $now) . "-----------" . date('Y-m-d H:i:s', $end));
				foreach ($arr as $val) {
					$option = [];
					if ($now < $val["times"] && $end > $val["times"]) {
						$option = ["agid" => $val['id'], "lev_code" => $val["levs"], "times" => $times, "isReals" => 2];
						$check_upgrade = Db::name($table)
							->where($option)
							->count();
						if (!$check_upgrade) {
							$option["stands"] = '{"1":[2,23,4,5,6,67]}';
							$option["createTime"] = $val['times'];
							Db::name($table)->insert($option);
						}
					}
				}
			}
			echo "运行正常...................！！！";
		} catch (\Exception $e) {
		}
	}
}
